package com.zprmb.udzt.adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.zprmb.udzt.BbtApplication;
import com.zprmb.udzt.ImageFloder;
import com.zprmb.udzt.ImageItem;
import com.zprmb.udzt.R;


public class PictureAdapter extends BaseAdapter {

	private ImageFloder currentImageFolder;
	private Activity context;

	public PictureAdapter(Activity context, ImageFloder currentImageFolder) {
		this.currentImageFolder = currentImageFolder;
		this.context = context;
	}

	public int getCount() {
		return currentImageFolder.images.size() + 1;
	}

	public Object getItem(int position) {
		return currentImageFolder.images.get(position - 1).path;
	}

	public long getItemId(int position) {
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder = null;
		if (convertView == null) {
			convertView = View.inflate(context,
					R.layout.selectimage_gridview_item, null);
			holder = new ViewHolder();
			holder.iv = (ImageView) convertView.findViewById(R.id.iv);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		if (position == 0) {
			holder.iv.setImageResource(R.drawable.bbt_selectimage_carom);
		} else {
			position = position - 1;
			final ImageItem item = currentImageFolder.images.get(position);
			System.out.println("select===" + item.path);
			BbtApplication.getInstance().display("file://" + item.path,
					holder.iv, R.drawable.bbt_selectimage_bg,1);
		}
		return convertView;
	}

	class ViewHolder {
		ImageView iv;
	}
}
